<!DOCTYPE html>
<html>

<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" rel="stylesheet" href="menu/meun.css">
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }

        body {
            background: #000 url(./assets/兴达八厂/背景兴达.jpg) no-repeat left top;
            background-size: 100%;
        }
    </style>
    <script src='../libs/jquery-3.4.1.min.js'></script> 
    <script src='../custom/configs/htconfig.js'></script>
    <script src='../custom/libs/echarts.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src="../conf/confURL.js"></script>
    <script src='../conf/dateTime.js'></script>
    <script>
        //获取url
        var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do";
        // 基底部门权限
        var deptUrl = domain + getDeptRequest;
        // 八厂 厂区编码
        let deptCodeEight = "XD1112";
        // 九厂 厂区编码
        let deptCodeNine = "XD1113";
        // 总部 编码
        let deptCodeHead = "headQuarters";
        let defaultDeptCode = "";
        //获取图纸
        var dataModel = new ht.DataModel();
        var graphView = new ht.graph.GraphView(dataModel);
        let factory5B;
        let factory5A;
        let factory2;
        let factory1;
        let factory8;
        let factory9;
        let factory3;
        let table;
        var warn = [];
        var echartsArr = [];
        var echart = [];
        let cos1;
        let cos2;
        let cos_1;
        let cos_2;
        let cos3;
        let cos_3;
        let pas1;
        let pas2;
        var H = [];
        var piep = [];
        let pie = [];
        let button1;
        let button2;
        let button3;
        let button4;
        let input3;
        let input4;
        var all_1;
        var all_2;
        function init() {
            graphView.addToDOM();
            ht.Default.xhrLoad('displays/智慧兴达/兴达八厂/工艺监控/process_base.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
                graphView.fitContent(true);
                tag();
                // 基地权限 获取有权限的部门编码
                getDeptCodeData();
                // 默认展示的报表数据
                var suv = defaultDeptCode;   //定义厂区全局编码
                get(suv, "year");     //界面默认数据
                getData7();
                getData8();
                openInterval();
                var a = getData6().HT_GY_ZZ_TREE;
                cd = menu(a);

                graphView.addInteractorListener(function (e) {
                    if (e.kind === 'clickData') {
                        // if (e.data._tag == 'generalFactory') {                           
                        //     suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else
                        // if (e.data._tag == 'electricFactory') {                           
                        //     suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else
                        // if (e.data._tag == 'factory1') {                           
                        //     suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else if (e.data._tag == 'factory2') {
                        //  suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else if (e.data._tag == 'factory2A') {
                        //     suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else if (e.data._tag == 'factory3') {
                        //     suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else if (e.data._tag == 'factory5A') {
                        //     suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else if (e.data._tag == 'factory5B') {
                        //      suv = deptCodeEight;
                        // get(suv, "year");
                        // }
                        // else 
                        if (e.data._tag == 'factory8') {      //厂区点击
                            suv = deptCodeEight;
                            get(suv, "year");
                        } else if (e.data._tag == 'factory9') {
                            suv = deptCodeNine;
                            get(suv, "year");
                        }else if("base_1" === e.data._tag || "base_21" === e.data._tag){  // 总部
                            suv = deptCodeHead;
                            get(suv, "year");
                            get(deptCodeHead);
                        } else if (e.data._tag == 'button1') {  //年月点击
                            button1.a("xs", true);
                            button2.a("xs", false);
                            getData1(suv, "year");
                        } else if (e.data._tag == 'button2') {
                            button1.a("xs", false);
                            button2.a("xs", true);
                            getData1(suv, "month");
                        } else if (e.data._tag == 'button3') {
                            getData4(suv, "year");
                            button3.a("xs", true);
                            button4.a("xs", false);
                        } else if (e.data._tag == 'button4') {
                            getData4(suv, "month");
                            button3.a("xs", false);
                            button4.a("xs", true);
                        } else if (e.data._tag == 'pas1') {    //饼图切换
                            cos1.s("2d.visible", true);
                            cos2.s("2d.visible", false);
                            pas1.a("a", true);
                            pas2.a("a", false);
                            clearInterval(t)
                        } else if (e.data._tag == 'pas2') {
                            cos1.s("2d.visible", false);
                            cos2.s("2d.visible", true);
                            pas1.a("a", false);
                            pas2.a("a", true);
                            clearInterval(t)
                        }
                    }
                });
                var t = setInterval(function () {    //饼图定时切换
                    if (pas2.a("a") == true) {
                        cos1.s("2d.visible", true);
                        cos2.s("2d.visible", false);
                        pas1.a("a", true);
                        pas2.a("a", false);
                    } else if (pas1.a("a") == true) {
                        cos1.s("2d.visible", false);
                        cos2.s("2d.visible", true);
                        pas1.a("a", false);
                        pas2.a("a", true);
                    }
                }, 1000 * 5);
            });
            //更新数据
            // setInterval(function () { getData(), getData1(), getData2()}, 1000 * 60 * 30);
            // setInterval(function () { getData3(), getData4(), getData5()}, 1000 * 60 * 5);
            //时间更新
            let dateTime
            setInterval(function () {
                dateTime = dataModel.getDataByTag("datetime")
                let time = updateTime();
                dateTime.a('time', time);
            }, 1000);
        }

        // 基地权限
        function getDeptCodeData() {
            $.ajax({
                url: deptUrl,
                type: "POST",
                headers: request_headers,
                data: {},
                async: false,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    res = JSON.parse(res);
                    if ('OK' === res._MSG_ && Boolean(res.deptCode)) {
                        defaultDeptCode = res.deptCode;
                    }
                },
                error: function (error) {
                }
            });
            return defaultDeptCode;
        }

        function get(code, ny) {
            getData(code),
                getData1(code, ny),
                getData2(code),
                getData3(code),
                getData4(code, ny),
                getData5(code)
        }
        function tag() {
            all_1 = dataModel.getDataByTag('all_1');
            all_2 = dataModel.getDataByTag('all_2');
            cos1 = dataModel.getDataByTag("cos1");//饼图块
            cos2 = dataModel.getDataByTag("cos2");
            cos_1 = dataModel.getDataByTag("cos_1");
            cos_2 = dataModel.getDataByTag("cos_2");
            cos3 = dataModel.getDataByTag("cos3");//点击块
            cos_3 = dataModel.getDataByTag("cos_3");
            pas1 = dataModel.getDataByTag("pas1");//饼图按钮
            pas2 = dataModel.getDataByTag("pas2");
            factory5B = dataModel.getDataByTag("factory5B")//厂区标签
            // factory2A = dataModel.getDataByTag("factory2A")
            factory5A = dataModel.getDataByTag("factory5A")
            factory2 = dataModel.getDataByTag("factory2")
            factory1 = dataModel.getDataByTag("factory1")
            factory8 = dataModel.getDataByTag("factory8")
            factory9 = dataModel.getDataByTag("factory9")
            factory3 = dataModel.getDataByTag("factory3")
            // generalFactory = dataModel.getDataByTag("generalFactory")
            // electricFactory = dataModel.getDataByTag("electricFactory")
            button1 = dataModel.getDataByTag("button1");//年月数据切换
            button2 = dataModel.getDataByTag("button2");
            button3 = dataModel.getDataByTag("button3");
            button4 = dataModel.getDataByTag("button4");
            for (let i = 1; i < 4; i++) {
                echartsArr.push(dataModel.getDataByTag("echart" + i));
            };
            for (let i = 1; i < 4; i++) {
                echart.push(dataModel.getDataByTag("echart_" + i));
            };

            for (let i = 1; i < 5; i++) {
                pie.push(dataModel.getDataByTag("pie" + i));
            };

            for (let i = 1; i < 5; i++) {
                piep.push(dataModel.getDataByTag("pie_" + i));
            };
            input3 = dataModel.getDataByTag('input3');//饼图文字
            input4 = dataModel.getDataByTag('input4');
            // input_3 = dataModel.getDataByTag('input3');
            // input_4 = dataModel.getDataByTag('input4');
            //获取表格框名字
            for (let i = 1; i < 13; i++) {
                H.push(dataModel.getDataByTag("H" + i));
            }
            //获取警告框
            for (let i = 1; i < 13; i++) {
                warn.push(dataModel.getDataByTag("warn" + i));
            }
            table = dataModel.getDataByTag("table") //八厂盘条库存  
        };
        //八厂盘条库存   
        function getData(code) {
            const table_1 = dataModel.getDataByTag("table_1")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_REPORT_PTKCTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[0].a("title", repData.totalTitle);
                        H[6].a("title", repData.totalTitle);
                        warn[0].s("2d.visible", false);
                        warn[6].s("2d.visible", false);
                        table.s("2d.visible", true);
                        table_1.s("2d.visible", true);
                        table.a("Data", repData.data);
                        table_1.a("Data", repData.data);
                    } else {
                        warn[0].s("2d.visible", true);
                        warn[6].s("2d.visible", true);
                        table.s("2d.visible", false);
                        table_1.s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[0].s("2d.visible", true)
                    warn[6].s("2d.visible", true)
                    table.s("2d.visible", false)
                    table_1.s("2d.visible", false)
                }
            });
        }
        //八厂模具模耗
        function getData1(code, ny) {
            const take1 = dataModel.getDataByTag("take1")
            const take_1 = dataModel.getDataByTag("take_1")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_REPORT_MJMHTJ",
                    deptCode: code,
                    mark: ny
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[1].a("title", repData.totalTitle);
                        H[7].a("title", repData.totalTitle);
                        warn[1].s("2d.visible", false);
                        warn[7].s("2d.visible", false);
                        take1.s("2d.visible", true);
                        take_1.s("2d.visible", true);
                        echartsArr[0].a("xData", repData.data.xdata);
                        echartsArr[0].a("data1", repData.data.cl);
                        echartsArr[0].a("data2", repData.data.zl);
                        echartsArr[0].a("data3", repData.data.ll);
                        echartsArr[0].a("data4", repData.data.sl);
                        echart[0].a("xData", repData.data.xdata);
                        echart[0].a("data1", repData.data.cl);
                        echart[0].a("data2", repData.data.zl);
                        echart[0].a("data3", repData.data.ll);
                        echart[0].a("data4", repData.data.sl);
                    } else {
                        warn[1].s("2d.visible", true);
                        warn[7].s("2d.visible", true);
                        take1.s("2d.visible", false);
                        take_1.s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[1].s("2d.visible", true);
                    warn[7].s("2d.visible", true);
                    take1.s("2d.visible", false);
                    take_1.s("2d.visible", false);
                }
            });
        }
        //八厂盘条投用占比
        function getData2(code) {
            const input1 = dataModel.getDataByTag("input1")
            const input2 = dataModel.getDataByTag("input2")
            const input_1 = dataModel.getDataByTag("input_1")
            const input_2 = dataModel.getDataByTag("input_2")
            const Eight = dataModel.getDataByTag("Eight")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_REPORT_PTTYZB01TJ",
                    deptCode: code
                },
                headers: request_headers,
                async: false,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[2].a("title", repData.title);
                        H[8].a("title", repData.title);
                        warn[2].s("2d.visible", false);
                        warn[8].s("2d.visible", false);
                        Eight.s("2d.visible", true);
                        pie[0].a("num", repData.data[0].num);
                        pie[1].a("num", repData.data[1].num);
                        input1.a("text", repData.data[0].totalC);
                        input2.a("text", repData.data[1].monthC);
                        piep[0].a("num", repData.data[0].num);
                        piep[1].a("num", repData.data[1].num);
                        input_1.a("text", repData.data[0].totalC);
                        input_2.a("text", repData.data[1].monthC);
                        pie[2].a("num", repData.data[2].num);
                        pie[3].a("num", repData.data[3].num);
                        input3.a("text", repData.data[2].yeargrade);
                        input4.a("text", repData.data[3].monthgrade);
                    } else {
                        warn[2].s("2d.visible", true);
                        warn[8].s("2d.visible", true);
                        Eight.s("2d.visible", false);
                    }
                },
                error: function (error) {
                    //console.log('err');
                }
            }
            );
            return repData
        }
        //八厂吨平断丝(表格)
        function getData3(code) {
            const tableone = dataModel.getDataByTag("tableone");
            const table_one = dataModel.getDataByTag("table_one");
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_REPORT_DPDS01TJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[3].a("title", repData.totalTitle);
                        H[9].a("title", repData.totalTitle);
                        warn[3].s("2d.visible", false);
                        warn[9].s("2d.visible", false);
                        tableone.s("2d.visible", true);
                        table_one.s("2d.visible", true);
                        tableone.a("num", repData.data.num);
                        tableone.a("gg", repData.data.guige);
                        table_one.a("num", repData.data.num);
                        table_one.a("gg", repData.data.guige);
                    } else {
                        warn[3].s("2d.visible", true);
                        warn[9].s("2d.visible", true);
                        tableone.s("2d.visible", false);
                        table_one.s("2d.visible", false);
                    }
                },
                error: function (error) {
                    //console.log('err');
                }
            });
        }
        //八厂吨平断丝
        function getData4(code, ny) {
            const take2 = dataModel.getDataByTag("take2")
            const take_2 = dataModel.getDataByTag("take_2")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_REPORT_DPDS02TJ",
                    deptCode: code,
                    mark: ny
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[4].a("title", repData.totalTitle);
                        H[10].a("title", repData.totalTitle);
                        warn[4].s("2d.visible", false);
                        warn[10].s("2d.visible", false);
                        take2.s("2d.visible", true);
                        take_2.s("2d.visible", true);
                        echartsArr[1].a("xData", repData.data.xdata);
                        echartsArr[1].a("data1", repData.data.HT);
                        echartsArr[1].a("data2", repData.data.NT);
                        echartsArr[1].a("data3", repData.data.ST);
                        echartsArr[1].a("data4", repData.data.UT);
                        echart[1].a("xData", repData.data.xdata);
                        echart[1].a("data1", repData.data.HT);
                        echart[1].a("data2", repData.data.NT);
                        echart[1].a("data3", repData.data.ST);
                        echart[1].a("data4", repData.data.UT);
                    } else {
                        warn[4].s("2d.visible", true);
                        warn[10].s("2d.visible", true);
                        take2.s("2d.visible", false);
                        take_2.s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[4].s("2d.visible", true);
                    warn[10].s("2d.visible", true);
                    take2.s("2d.visible", false);
                    take_2.s("2d.visible", false);
                }
            });
        }
        //八厂CPK≥1.33占比
        function getData5(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_REPORT_CPKZBTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[5].a("title", repData.title);
                        H[11].a("title", repData.title);
                        warn[5].s("2d.visible", false);
                        warn[11].s("2d.visible", false);
                        echartsArr[2].s("2d.visible", true);
                        echart[2].s("2d.visible", true);
                        echartsArr[2].a("xAxis", repData.data.xdata);
                        echartsArr[2].a("yAxis1", repData.data.rksdu);
                        echartsArr[2].a("yAxis2", repData.data.slry);
                        echart[2].a("xAxis", repData.data.xdata);
                        echart[2].a("yAxis1", repData.data.rksdu);
                        echart[2].a("yAxis2", repData.data.slry);
                    } else {
                        warn[5].s("2d.visible", true);
                        warn[11].s("2d.visible", true);
                        echartsArr[2].s("2d.visible", false);
                        echart[2].s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[5].s("2d.visible", true);
                    warn[11].s("2d.visible", true);
                    echartsArr[2].s("2d.visible", false);
                    echart[2].s("2d.visible", false);
                }
            });
        }
        //菜单接口     
        function getData6() {
            // let tree = dataModel.getDataByTag("tree")
            // let treeNode = dataModel.getDataByTag("treeNode")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_ZZ_TREE"
                },
                headers: request_headers,
                async: false,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res, handleJson);
                    if (repData._MSG_ === 'OK' && repData.visible === true) {
                        // treeNode.s("2d.selectable", true)
                        // tree.a("ht.dataSource", repData.HT_GY_ZZ_TREE)
                        document.getElementById("node").style.display = "block"
                    } else {
                        // treeNode.s("2d.selectable", false)
                        document.getElementById("node").style.display = "none"
                    }
                },
                error: function (error) {
                    // treeNode.s("2d.selectable", false)
                    document.getElementById("node").style.display = "none"
                }
            });
            return repData
        }
        //厂区上的跳转链接接口
        function getData7() {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_ZZ_MAPTAB"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_GY_ZZ_MAPTAB.visible == "true") {
                        factory1.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                        factory5B.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                        factory5A.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                        factory2.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                        factory8.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                        factory9.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                        factory3.s("label", repData.HT_GY_ZZ_MAPTAB.urlMap);
                      
                    }
                },
                error: function (error) {
                    //  console.log('err');
                }
            });
        }
        //返回按钮
        function getData8() {
            const backButton = dataModel.getDataByTag("backButton")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_GY_JD_BUTTON_RETURN"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_GY_JD_BUTTON_RETURN.visible == "true") {
                        backButton.a("url", repData.HT_GY_JD_BUTTON_RETURN.data.url);
                        backButton.s("2d.visible", repData.HT_GY_JD_BUTTON_RETURN.visible);

                    }
                },
                error: function (error) {
                    //console.log('err');
                }
            });
        }
        //表格自动滚动
        function tableRun() {
            let tabledata = table.a("Data");
            var old = table.a('ht.translateY');
            table.a('ht.translateY', old - 44);
            tabledata.push(tabledata[0]);
            tabledata.splice(0, 1)
            table.a("Data", tabledata);
            table.a('ht.translateY', old);
        }
        //重新打开定时器，播放滚动
        function openInterval() {
            tableTimer = setInterval(tableRun, 2000);
        }

    </script>
</head>
<body onload='setTimeout(init, 300)'>
    <div id="ct">
        <div id="abc" style="display:none;height:100%;width:95%;">
            <div id="app"
                style="background:url(menu/tree3.png) no-repeat; background-size:100% 100%;position: absolute;z-index:20; width: 11%; height:85%;top:10.5%;overflow: hidden;">
                <span id="total" style="font-size:18px"; >兴达公司</span>
                <img class="lin" src="menu/line.png">
                </br></br></br></br>
            </div>
        </div>
        <div id="node"
            style="left:0px;display:block;background-color:rgba(red, green, blue, 0);position:absolute;width: 33px;height: 650px;top: 80px;z-index: 100;">
        </div>
    </div>
</body>

</html>